package calendar.dan.com.calendar;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class CalendarAdapter extends BaseAdapter {
    private int num;
    private Context context;
    private List<String> markList = new ArrayList<>();
    private SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月");


    public CalendarAdapter(Context context, int num) {
		this.context = context;
//		this.repastList = repastList;
        this.num = num;

        markList.add("2015-01-06");
        markList.add("2015-01-10");
        markList.add("2015-01-15");
        markList.add("2015-01-26");
        markList.add("2015-01-30");
        markList.add("2015-01-06");
        markList.add("2015-01-26");

    }


    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        //	return repastList == null ? 0 : repastList.size();
        return num;
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return num;
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(final int position, View view, ViewGroup arg2) {
        ViewHolder holder = null;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.calendarlist_item, null);
            holder = new ViewHolder();
            holder.tv_date = (TextView)view.findViewById(R.id.tv_date);
            holder.calendarView = (KCalendar2)view.findViewById(R.id.calendarView);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, position);
        holder.calendarView.init(calendar,markList);
 //       holder.calendarView.invalidate();
//        holder.calendarView.setCalendarDate();
        holder.tv_date.setText(format.format(calendar.getTime()));

        holder.calendarView.setOnCalendarClickListener(new MyCalendarClickListener());

        return view;
    }
    public final class ViewHolder {
        public TextView name;
        public TextView tv_date;
        private KCalendar2 calendarView;
    }

    class MyCalendarClickListener implements KCalendar2.OnCalendarClickListener {

        @Override
        public void onCalendarClick(int row, int col, String dateFormat) {
            Log.i("222222222222222222","22222222222222dateFormatdateFormat==="+dateFormat);
        }
    }


}
